#include<iostream>
#include<vector>
#include<algorithm>
#include<string>
#include<math.h>
using namespace std;

class Solution {
public:
    int reverse(int x) {
        //判断符号
        string temp;
        string maxvalue = to_string(int(pow(2,31)-1));
        string minvalue = to_string(int(pow(2,31)-1));
        *minvalue.rbegin() = '8';
        int status = 1;
        if(x>=0){
            temp = to_string(x);
            func(temp,0,temp.size()-1);
            if(temp.size()<maxvalue.size()){
                return stoi(temp); 
            }
            else if(temp.size()==maxvalue.size()&&temp<maxvalue){
                return stoi(temp);
            }

        }
        else{
            status = 0;
            temp = to_string(x);
            temp = string(temp.begin()+1,temp.end());
            func(temp,0,temp.size()-1);
            if(temp.size()<minvalue.size()){
                return stoi(temp)*-1;
            }
            else if(temp.size()==minvalue.size()&&temp<minvalue){
                return stoi(temp)*-1;
            }
        }
        return 0;

    }
    void func(string& temp,int i,int j){
        while(i<j){
            char tempchar = temp[i];
            temp[i] = temp[j];
            temp[j] = tempchar;
            ++i;
            --j;
        }
    }
};

int main(){
    Solution S;
    int A = pow(2,31)-1;
    cout<<S.reverse(A)<<endl;
}